package com.youlai.quarkus.system.converter;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.quarkus.system.model.entity.SysDictType;
import com.youlai.quarkus.system.model.form.DictTypeForm;
import com.youlai.quarkus.system.model.vo.DictTypePageVO;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 字典类型对象转换器
 *
 * @author haoxr
 * @since 2022/6/8
 */
@ApplicationScoped
public class DictTypeConverter {
    public Page<DictTypePageVO> entity2Page(Page<SysDictType> page) {
        if (page == null) {
            return null;
        } else {
            Page<DictTypePageVO> page1 = new Page();
            page1.setPages(page.getPages());
            page1.setRecords(this.sysDictTypeListToDictTypePageVOList(page.getRecords()));
            page1.setTotal(page.getTotal());
            page1.setSize(page.getSize());
            page1.setCurrent(page.getCurrent());
            page1.setSearchCount(page.searchCount());
            page1.setOptimizeCountSql(page.optimizeCountSql());
            List<OrderItem> list1 = page.orders();
            if (list1 != null) {
                page1.setOrders(new ArrayList(list1));
            }

            page1.setMaxLimit(page.maxLimit());
            page1.setCountId(page.countId());
            return page1;
        }
    }

    public DictTypeForm entity2Form(SysDictType entity) {
        if (entity == null) {
            return null;
        } else {
            DictTypeForm dictTypeForm = new DictTypeForm();
            dictTypeForm.setId(entity.getId());
            dictTypeForm.setName(entity.getName());
            dictTypeForm.setCode(entity.getCode());
            dictTypeForm.setStatus(entity.getStatus());
            dictTypeForm.setRemark(entity.getRemark());
            return dictTypeForm;
        }
    }

    public SysDictType form2Entity(DictTypeForm entity) {
        if (entity == null) {
            return null;
        } else {
            SysDictType sysDictType = new SysDictType();
            sysDictType.setId(entity.getId());
            sysDictType.setName(entity.getName());
            sysDictType.setCode(entity.getCode());
            sysDictType.setStatus(entity.getStatus());
            sysDictType.setRemark(entity.getRemark());
            return sysDictType;
        }
    }

    protected DictTypePageVO sysDictTypeToDictTypePageVO(SysDictType sysDictType) {
        if (sysDictType == null) {
            return null;
        } else {
            DictTypePageVO dictTypePageVO = new DictTypePageVO();
            dictTypePageVO.setId(sysDictType.getId());
            dictTypePageVO.setName(sysDictType.getName());
            dictTypePageVO.setCode(sysDictType.getCode());
            dictTypePageVO.setStatus(sysDictType.getStatus());
            return dictTypePageVO;
        }
    }

    protected List<DictTypePageVO> sysDictTypeListToDictTypePageVOList(List<SysDictType> list) {
        if (list == null) {
            return null;
        } else {
            List<DictTypePageVO> list1 = new ArrayList(list.size());
            Iterator var3 = list.iterator();

            while(var3.hasNext()) {
                SysDictType sysDictType = (SysDictType)var3.next();
                list1.add(this.sysDictTypeToDictTypePageVO(sysDictType));
            }

            return list1;
        }
    }
}
